package jianzhiOffer;

public class num21 {
    public int[] exchange(int[] nums) {
        int index1 = 0;
        int index2 = nums.length - 1;
        while(index1 < index2) {
            while(nums[index1] % 2 == 1 && index1 < index2) {
                index1 ++;
            }
            while(index1 < index2 && nums[index2] % 2 == 0) {
                index2 --;
            }
            if(index1 < index2) {
                int temp = nums[index2];
                nums[index2] = nums[index1];
                nums[index1] = temp;
                index1 ++;
                index2 --;
            }
        }
        return nums;
    }
}
